package org.Yiran.timetale_re.block.crystal;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.ItemLike;
import org.Yiran.timetale_re.block.crystal.base.CrystalBaseBlock;
import org.Yiran.timetale_re.item.ItemsRegister;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;

/**
 * 时间水晶方块
 * <p>
 * 这个类实现了时间水晶方块，继承自CrystalBaseBlock基类。
 * 时间水晶是一种特殊的水晶，具有独特的属性和掉落物。
 * </p>
 */
public class TimeCrystalBlock extends CrystalBaseBlock {
    // 等级属性，定义水晶的强度等级（1-3级）
    public static final IntegerProperty LEVEL = IntegerProperty.create("level", 1, 3);
    
    // 水晶等级
    private final int level;

    /**
     * 默认构造函数
     * 使用等级1创建时间水晶方块
     */
    public TimeCrystalBlock() {
        this(1);
    }

    /**
     * 带等级的构造函数
     * 
     * @param level 水晶等级 (1-3)
     */
    public TimeCrystalBlock(int level) {
        super();
        this.level = level;

        // 覆盖默认状态中的等级值
        this.registerDefaultState(this.stateDefinition.any()
                .setValue(FACING, Direction.UP)
                .setValue(LEVEL, level)
                .setValue(BlockStateProperties.WATERLOGGED, false));
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        super.createBlockStateDefinition(builder);
    }
    
    @Override
    public IntegerProperty getLevelProperty() {
        return LEVEL;
    }

    @Override
    public Item getDropItem() {
        return ItemsRegister.TIME_GEM.get();
    }

    @Override
    @SuppressWarnings("deprecation")
    public @NotNull ItemStack getCloneItemStack(@NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull BlockState state) {
        return new ItemStack(ItemsRegister.TIME_GEM.get());
    }

    // ==================== 访问器方法 ====================

    /**
     * 获取水晶等级
     * 
     * @return 水晶等级
     */
    public int getLevel() {
        return level;
    }
}